{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "dfa425ad-7a37-4be0-86a2-53694449294f",
   "metadata": {},
   "source": [
    "# 函数\n",
    "## 函数的概念\n",
    "- 函数最重要的目的是为了方便我们重复使用相同的一段程序（程序的复用性），它可以对程序进行结构化处理，将一些特定功能的代码，巧妙的封装成一个方便管理的代码块。\n",
    "## 函数的编写和定义\n",
    "- 所谓函数，就是把具有独立功能的代码块组成一个小模块，在需要的时候调用\n",
    "- 函数的使用包含两个步骤\n",
    "- 1.定义函数--封装独立功能\n",
    "- 2.调用函数--享受封装的成果\n",
    "- 函数的作用，在开发程序时，使用函数可以提高编写的效率以及代码的重用\n",
    "## 函数的创建\n",
    "##### def 函数名(输入参数):\n",
    "#####     函数体\n",
    "#####     [return xxx]\n",
    "## 函数的定义\n",
    "##### def 函数名([参数列表]):     # 关键字def 标志着函数的开始\n",
    "#####     [\"文档字符串\"]\n",
    "#####     函数体\n",
    "#####     [return 语句]\n",
    "\n",
    "##### 函数名：函数的唯一标识符，命名方式遵循标识符的命名规则\n",
    "##### 参数列表：可以有多个、一个或多个参数，多个参数之间使用逗号分隔\n",
    "##### 文档字符串：用于描述函数的功能，可以省略(一般都不写)\n",
    "##### 函数体：函数每次调用时执行的代码，由一行或者多行Python语句构成\n",
    "##### return语句：标志着函数的结束，用于将函数中的数据返回给函数的调用者\n",
    "\n",
    "#### 注意：函数调用不能放在函数定义的上方，先定义后调用\n",
    "\n",
    "## 函数的种类\n",
    "- 无参无返回值函数\n",
    "- 无参有返回值函数\n",
    "- 有参无返回值函数\n",
    "- 有参有返回值函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "301af170-6195-4af6-91ef-e92d51263bfe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<function method_val1 at 0x000001DF26E00F40>\n"
     ]
    }
   ],
   "source": [
    "# 定义无参无返回值函数\n",
    "def method_val1():\n",
    "    num_a = 10\n",
    "    num_b = 20\n",
    "    print('这是一个无参无返回值函数')     # 说明该函数返回值的内容就是两个整型变量的和\n",
    "\n",
    "print(method_val1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e1f7913a-3c6b-423f-a6a4-517107ab5391",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<function method_val2 at 0x000001DF26E00CC0>\n"
     ]
    }
   ],
   "source": [
    "# 定义无参有返回值函数\n",
    "def method_val2():\n",
    "    num_a = 10\n",
    "    num_b = 20\n",
    "    return num_a + num_b     # 说明该函数返回值的内容就是两个整型变量的和\n",
    "\n",
    "print(method_val2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "11c2c38d-68c1-4533-9980-b4f752344ea9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "# 定义有参无返回值函数\n",
    "def method_val3(num_a, num_b):\n",
    "    print(num_a + num_b)    # 此时并没有定义num_a和num_b这两个变量，仅仅只是编写了参数，进行输出\n",
    "\n",
    "method_val3(2, 5)    # 在调用有参函数的时候，一定要给该函数传递真实的参数，否则会报错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "98f573e0-6cf2-4fc5-8815-28f9dde63c24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.75\n"
     ]
    }
   ],
   "source": [
    "# 定义有参有返回值函数\n",
    "def method_val4(num_a, num_b):     # 其中num_a和num_b表示的是形参\n",
    "    return(num_a + num_b) / num_b     # 返回两个参数的和除以其中一个参数\n",
    "\n",
    "print(method_val4(3, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "df92a109-1219-4934-9cc4-7b3072aa33c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'function'>\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def get_info():    # 定义无参无返回值函数\n",
    "    pass    # 此函数没有主体代码，定义时需要写上pass\n",
    "print(type(get_info))    #<class 'function'>表示当前的get_info是一个函数\n",
    "print(get_info())    # None表示当前函数没有返回值，所以是None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4e4db6b7-ae32-4b99-8d6c-e1d11a8a16ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30\n",
      "-10\n",
      "200\n",
      "0.5\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def get_info2():\n",
    "    a = 10\n",
    "    b = 20\n",
    "    print(a + b)\n",
    "    print(a - b)\n",
    "    print(a * b)\n",
    "    print(a / b)\n",
    "\n",
    "print(get_info2())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ca876e81-484c-4d19-af0e-531c72c76fef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HelloWord!\n"
     ]
    }
   ],
   "source": [
    "# 存在返回值的函数\n",
    "def get_info3():\n",
    "    pass\n",
    "    return \"HelloWord!\"\n",
    "\n",
    "print(get_info3())    # 如果函数有返回值，则当打印该函数的时候，输出的结果一定是返回值的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "31f196d5-0abc-4c04-ae3a-fc06eb9dd6be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello AI Word!\n",
      "AI是新世界世界竞争中的基石\n"
     ]
    }
   ],
   "source": [
    "# 了解了函数的返回值之后，实际上函数还可以相互调用\n",
    "# coding:UTF-8\n",
    "def say_hello():\n",
    "    \"\"\"\n",
    "    定义一个信息打印函数，该函数不反悔任何数据\n",
    "    \"\"\"\n",
    "    print(\"Hello AI Word!\")\n",
    "\n",
    "def get_infomsg():\n",
    "    \"\"\"\n",
    "    定义一个获取信息的功能函数\n",
    "    \"\"\"\n",
    "    say_hello()\n",
    "    return \"AI是新世界世界竞争中的基石\"\n",
    "\n",
    "# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\b\\c\\d都可以\n",
    "return_data = get_infomsg()    # 引用传递\n",
    "print(return_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb19f899-109e-412d-8593-b96ef6ada97c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 任何函数都会有返回数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e36e5b39-a7a6-47f0-bc0d-b18829898f0d",
   "metadata": {},
   "source": [
    "## 函数参数的传递\n",
    "- 定义函数的主要目的在于进行数据处理，因为大多数函数都会接受相关参数，这就要求"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f1531b8d-52fa-4611-9358-5c8ac967c1ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【ECHO】标题路径地址：天气网、ip地址：192.168.177.199\n",
      "【ECHO】标题路径地址：天气网、ip地址：192.168.177.199\n"
     ]
    }
   ],
   "source": [
    "# 定义带参数的函数\n",
    "# coding:UTF-8\n",
    "def echo(title, url):\n",
    "    \"\"\"\n",
    "    实现数据的回显操作，在接受的数据前追加ECHO信息返回\n",
    "    ：param title: 要回显的标题信息\n",
    "    ：param url: 要回显的网页路径信息\n",
    "    : return: 处理后的ECHO信息\n",
    "    \"\"\"\n",
    "    return \"【ECHO】标题路径地址：{}、ip地址：{}\".format(title, url)\n",
    "\n",
    "# 按照函数丁——1参数顺序传入需要的参数\n",
    "print(echo(\"天气网\",'192.168.177.199'))    # 调用函数\n",
    "\n",
    "print(echo(url='192.168.177.199', title=\"天气网\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a302e97-6cdb-43ed-a1e0-e88af06fcfc3",
   "metadata": {},
   "source": [
    "### 函数的覆盖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ffa051af-b096-4bd3-b723-b0b9cc634bb6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，派森\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def test():\n",
    "    print('hello world')\n",
    "\n",
    "def test():\n",
    "    print('你好，派森')\n",
    "\n",
    "demo_project = test()\n",
    "print(demo_project)    # 因为该函数没有返回值，所以打印的是None"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3e3a266-6de9-4546-bd20-bb1f3fd565ff",
   "metadata": {},
   "source": [
    "#### 函数参数深入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "350ebae7-3b7c-49a5-b438-eac9d2c47de5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def sum_2_num():\n",
    "    num1 = 10\n",
    "    num2 = 20\n",
    "    return num1 + num2\n",
    "\n",
    "    print('%d + %d = %d' % (num1, num2, result))    # 因为该语句处在return语句的后面，所以永远不可能执行\n",
    "\n",
    "sum_2_num()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "99548513-1736-4a0c-91cb-f7bfcc421fea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "较大的数是： 96\n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def function_method():\n",
    "    print('这是一个无参函数')\n",
    "\n",
    "def test(num1, num2):\n",
    "    if num1 > num2:\n",
    "        print('较大的数是：', num1)\n",
    "    else:\n",
    "        print('较大的数是：', num2)\n",
    "\n",
    "test(12, 96)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a1fca4c0-0f13-4702-9455-025b2165d364",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "sum_2_num() takes 0 positional arguments but 2 were given",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[24], line 7\u001b[0m\n\u001b[0;32m      3\u001b[0m     result \u001b[38;5;241m+\u001b[39m num1 \u001b[38;5;241m+\u001b[39m num2\n\u001b[0;32m      5\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m + \u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m = \u001b[39m\u001b[38;5;132;01m%d\u001b[39;00m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m%\u001b[39m (num1, num2, result))\n\u001b[1;32m----> 7\u001b[0m sum_2_num(\u001b[38;5;241m30\u001b[39m,\u001b[38;5;241m20\u001b[39m)\n",
      "\u001b[1;31mTypeError\u001b[0m: sum_2_num() takes 0 positional arguments but 2 were given"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def sum_2_num():\n",
    "    result + num1 + num2\n",
    "\n",
    "    print('%d + %d = %d' % (num1, num2, result))\n",
    "\n",
    "sum_2_num(30,20)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89f73d0f-2c3f-4f46-b485-11ceb6dde823",
   "metadata": {},
   "source": [
    "## 形参和实参\n",
    "- 形参： 定义函数时，小括号中的数据，是用来接收实参用的，在函数内部作为变量使用\n",
    "  定义参数的时候传递的参数叫做形式参数，也叫形参\n",
    "- 实参：调用函数时，小括号中的数据，是用来把数据传递到函数内部用的\n",
    "  调用函数时传递的参数叫做实际参数，也叫做实参，在去调用函数的时候，实参会把形参替换\n",
    "  如果在定义函数时，有形参，在调用时，函数必须传递真实的数据，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "97cb15a7-d6c3-4a02-ad85-22464162f2ea",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "test_def() takes 2 positional arguments but 5 were given",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[25], line 5\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtest_def\u001b[39m(num1, num2, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m      3\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m (num1 \u001b[38;5;241m+\u001b[39m num2) \u001b[38;5;241m/\u001b[39m kwargs\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(test_def(\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m3\u001b[39m, \u001b[38;5;241m4\u001b[39m, \u001b[38;5;241m5\u001b[39m))\n",
      "\u001b[1;31mTypeError\u001b[0m: test_def() takes 2 positional arguments but 5 were given"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def test_def(num1, num2, **kwargs):\n",
    "    return (num1 + num2) / kwargs\n",
    "\n",
    "print(test_def(1, 2, 3, 4, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "a629f01e-f830-4cf7-bfb2-615b447005fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "用户姓名：AI\n",
      "喜欢的技术：\n",
      "\t|- mlearng: skylearn, 随机森林,鸢尾花,k-mean,线性回归..\n",
      "\t|- clearng: CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def print_info(name, **urls):\n",
    "    \"\"\"\n",
    "    定义了一个不定长参数的函数值\n",
    "    ：param name: 要输出的姓名信息\n",
    "    : param urls: 一组key=value的信息组合\n",
    "    \"\"\"\n",
    "    print(\"用户姓名：%s\" % name)\n",
    "    print(\"喜欢的技术：\")\n",
    "    for key, value in urls.items():\n",
    "        print(\"\\t|- %s: %s\" % (key, value))\n",
    "\n",
    "print_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f371e0f-7b18-4323-a7ce-e6c082b2381d",
   "metadata": {},
   "source": [
    "### 混合编写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e99bfd2f-48fb-414c-a9c7-91616d4251c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "用户姓名：张三，年龄：20\n",
      "用户兴趣：卷积神经网络、人工智能对话、大模型、\n",
      " 喜欢学习的知识点：\n",
      "\t | - mlearng: skylearn,随机森林,鸢尾花,k-mean,线性回归..\n",
      "\t | - clearng: CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\n",
    "    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\n",
    "    print(\"用户兴趣：\", end='')    # 信息输出\n",
    "    for item in inst:   # 遍历可变参数\n",
    "        print(item, end='、')    # 打印序列当中的每个元素\n",
    "    print(\"\\n 喜欢学习的知识点：\")    # 信息输出\n",
    "    for key, value in urls.items():\n",
    "        print(\"\\t | - %s: %s\" % (key, value))    # 输出映射项\n",
    "\n",
    "# 调用函数\n",
    "print_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6d14c7b-4248-4c1f-b2f7-5a97fbd510c8",
   "metadata": {},
   "source": [
    "## 函数变量转换操作\n",
    "在Python中，函数中的局部变量，可以通过一定的操作方法，转换成全局变量，来完成一些特定的功能\n",
    "##### 变量的作用域\n",
    "变量的名称解析的LEGB原则\n",
    "- L()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f81f8b44-d2f2-4db1-99cf-3ba7098b6335",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "2e16e771-f89e-4716-bf0a-37806863c3d2",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "1ee5bb05-b38b-4067-b536-fde0d07b4a2b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'__name__': '__main__', '__doc__': 'Automatically created module for IPython interactive environment', '__package__': None, '__loader__': None, '__spec__': None, '__builtin__': <module 'builtins' (built-in)>, '__builtins__': <module 'builtins' (built-in)>, '_ih': ['', \"# 无参无返回值函数\\n# coding:UTF-8\\ndef method_val1():\\n    num_a = 10    # 定义一个整数的变量\\n    num_b = 20\\n    print('这是一个无参无返回值函数')    # 输出语句\\n    print(num_a + num_b)    # 输出语句 变量的和\\n\\nmethod_val1    # 函数的调用\", '# 定义无参有返回值函数\\ndef method_val2():\\n    num_a = 10\\n    num_b = 20\\n    return num_a + num_b     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nmethod_val2', '# 定义无参有返回值函数\\ndef method_val2():\\n    num_a = 10\\n    num_b = 20\\n    return num_a + num_b     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nprint(method_val2)', \"# 定义一个无参无返回值函数\\ndef method_val1():\\n    num_a = 10\\n    num_b = 20\\n    print('这是一个无参无返回值函数')     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nprint(method_val1)\", '# 定义有参无返回值函数\\ndef method_val3(num_a, num_b):\\n    print(num_a, num_b)    # 此时并没有定义num_a和num_b这两个变量，仅仅只是编写了参数，进行输出\\n\\nmethod_val3(2, 5)    # 在调用有参函数的时候，一定要给该函数传递真实的参数，否则会报错', '# 定义有参无返回值函数\\ndef method_val3(num_a, num_b):\\n    print(num_a + num_b)    # 此时并没有定义num_a和num_b这两个变量，仅仅只是编写了参数，进行输出\\n\\nmethod_val3(2, 5)    # 在调用有参函数的时候，一定要给该函数传递真实的参数，否则会报错', '# 定义有参有返回值函数\\ndef method_val4(num_a, num_b):     # 其中num_a和num_b表示的是形参\\n    return(num_a + num_b) / num_b     # 返回两个参数的和除以其中一个参数\\n\\nprint(method_val4(3, 4))', \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", '# 存在返回值的函数\\ndef get_info3():\\n    pass\\n    return \"HelloWord!\"\\n\\nprint(get_info3())', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_heool()\\n    return \"AI是新世界世界竞争中的基石\"', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递\\nprint(return_data)', '# 定义带参数的函数\\n# coding:UTF-8\\ndef echo(title, url):\\n    \"\"\"\\n    实现数据的回显操作，在接受的数据前追加ECHO信息返回\\n    ：param title: 要回显的标题信息\\n    ：param url: 要回显的网页路径信息\\n    : return: 处理后的ECHO信息\\n    \"\"\"\\n    return \"【ECHO】标题路径地址：{}、ip地址：{}\".format(title, url)\\n\\n# 按照函数丁——1参数顺序传入需要的参数\\nprint(echo(\"天气网\",\\'192.168.177.199\\'))    # 调用函数\\n\\nprint(echo(url=\\'192.168.177.199\\', title=\"天气网\"))', \"# coding:UTF-8\\ndef sum_2_num():\\n    num1 = 10\\n    num2 = 20\\n    return num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))    # 因为该语句处在return语句的后面，所以永远不可能执行\\n\\nsum_2_num\", \"# coding:UTF-8\\ndef sum_2_num():\\n    num1 = 10\\n    num2 = 20\\n    return num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))    # 因为该语句处在return语句的后面，所以永远不可能执行\\n\\nsum_2_num()\", \"# coding:UTF-8\\ndef function_method():\\n    print('这是一个无参函数')\\n\\ndef test(num1, num2):\\n    if num1 > num2:\\n        print('较大的数是：', num1)\\n    else:\\n        print('较大的数是：', num2)\\n\\ntest(12, 96)\", \"# coding:UTF-8\\ndef test():\\n    print('hello world')\\n\\ndef test():\\n    print('你好，派森')\\n\\ndemo_project = test()\\nprint(demo_project)    # 因为该函数没有返回值，所以打印的是None\", '# coding:UTF-8\\ndef get_info2():\\n    a = 10\\n    b = 20\\n    print(a + b)\\n    print(a - b)\\n    print(a * b)\\n    print(a / b)\\n\\nprint(get_info2)', '# coding:UTF-8\\ndef get_info2():\\n    a = 10\\n    b = 20\\n    print(a + b)\\n    print(a - b)\\n    print(a * b)\\n    print(a / b)\\n\\nprint(get_info2())', \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info()))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info)    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", \"# coding:UTF-8\\ndef sum_2_num():\\n    result + num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))\\n\\nsum_2_num(30,20)\", '# coding:UTF-8\\ndef test_def(num1, num2, **kwargs):\\n    return (num1 + num2) / kwargs\\n\\nprint(test_def(1, 2, 3, 4, 5))', '# coding:UTF-8\\ndef print_info(name, **urls):\\n    \"\"\"\\n    定义了一个不定长参数的函数值\\n    ：param name: 要输出的姓名信息\\n    : param urls: 一组key=value的信息组合\\n    \"\"\"\\n    print(\"用户姓名：%s\" % name)\\n    print(\"喜欢的技术：\")\\n    for key, value in urls.items():\\n        print(\"\\\\t|- %s: %s\" % (key, value))\\n\\nprint_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clrarng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clrarng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# coding:UTF-8\\ndef print_info(name, **urls):\\n    \"\"\"\\n    定义了一个不定长参数的函数值\\n    ：param name: 要输出的姓名信息\\n    : param urls: 一组key=value的信息组合\\n    \"\"\"\\n    print(\"用户姓名：%s\" % name)\\n    print(\"喜欢的技术：\")\\n    for key, value in urls.items():\\n        print(\"\\\\t|- %s: %s\" % (key, value))\\n\\nprint_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# 使用globle()函数与locals()函数进行操作\\n# coding:UTF-8\\nnumber = 100\\ndef print_var():\\n    num = 30\\n    info = \"测试的字符串内容\"\\n    print(globals())\\n    print(locals())\\n\\n# 调用函数\\nprint_var()'], '_oh': {1: <function method_val1 at 0x000001DF26E005E0>, 2: <function method_val2 at 0x000001DF26E00D60>, 15: <function sum_2_num at 0x000001DF26E011C0>, 16: 30}, '_dh': [WindowsPath('C:/Users/许家彗/A_Course')], 'In': ['', \"# 无参无返回值函数\\n# coding:UTF-8\\ndef method_val1():\\n    num_a = 10    # 定义一个整数的变量\\n    num_b = 20\\n    print('这是一个无参无返回值函数')    # 输出语句\\n    print(num_a + num_b)    # 输出语句 变量的和\\n\\nmethod_val1    # 函数的调用\", '# 定义无参有返回值函数\\ndef method_val2():\\n    num_a = 10\\n    num_b = 20\\n    return num_a + num_b     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nmethod_val2', '# 定义无参有返回值函数\\ndef method_val2():\\n    num_a = 10\\n    num_b = 20\\n    return num_a + num_b     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nprint(method_val2)', \"# 定义一个无参无返回值函数\\ndef method_val1():\\n    num_a = 10\\n    num_b = 20\\n    print('这是一个无参无返回值函数')     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nprint(method_val1)\", '# 定义有参无返回值函数\\ndef method_val3(num_a, num_b):\\n    print(num_a, num_b)    # 此时并没有定义num_a和num_b这两个变量，仅仅只是编写了参数，进行输出\\n\\nmethod_val3(2, 5)    # 在调用有参函数的时候，一定要给该函数传递真实的参数，否则会报错', '# 定义有参无返回值函数\\ndef method_val3(num_a, num_b):\\n    print(num_a + num_b)    # 此时并没有定义num_a和num_b这两个变量，仅仅只是编写了参数，进行输出\\n\\nmethod_val3(2, 5)    # 在调用有参函数的时候，一定要给该函数传递真实的参数，否则会报错', '# 定义有参有返回值函数\\ndef method_val4(num_a, num_b):     # 其中num_a和num_b表示的是形参\\n    return(num_a + num_b) / num_b     # 返回两个参数的和除以其中一个参数\\n\\nprint(method_val4(3, 4))', \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", '# 存在返回值的函数\\ndef get_info3():\\n    pass\\n    return \"HelloWord!\"\\n\\nprint(get_info3())', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_heool()\\n    return \"AI是新世界世界竞争中的基石\"', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递', '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递\\nprint(return_data)', '# 定义带参数的函数\\n# coding:UTF-8\\ndef echo(title, url):\\n    \"\"\"\\n    实现数据的回显操作，在接受的数据前追加ECHO信息返回\\n    ：param title: 要回显的标题信息\\n    ：param url: 要回显的网页路径信息\\n    : return: 处理后的ECHO信息\\n    \"\"\"\\n    return \"【ECHO】标题路径地址：{}、ip地址：{}\".format(title, url)\\n\\n# 按照函数丁——1参数顺序传入需要的参数\\nprint(echo(\"天气网\",\\'192.168.177.199\\'))    # 调用函数\\n\\nprint(echo(url=\\'192.168.177.199\\', title=\"天气网\"))', \"# coding:UTF-8\\ndef sum_2_num():\\n    num1 = 10\\n    num2 = 20\\n    return num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))    # 因为该语句处在return语句的后面，所以永远不可能执行\\n\\nsum_2_num\", \"# coding:UTF-8\\ndef sum_2_num():\\n    num1 = 10\\n    num2 = 20\\n    return num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))    # 因为该语句处在return语句的后面，所以永远不可能执行\\n\\nsum_2_num()\", \"# coding:UTF-8\\ndef function_method():\\n    print('这是一个无参函数')\\n\\ndef test(num1, num2):\\n    if num1 > num2:\\n        print('较大的数是：', num1)\\n    else:\\n        print('较大的数是：', num2)\\n\\ntest(12, 96)\", \"# coding:UTF-8\\ndef test():\\n    print('hello world')\\n\\ndef test():\\n    print('你好，派森')\\n\\ndemo_project = test()\\nprint(demo_project)    # 因为该函数没有返回值，所以打印的是None\", '# coding:UTF-8\\ndef get_info2():\\n    a = 10\\n    b = 20\\n    print(a + b)\\n    print(a - b)\\n    print(a * b)\\n    print(a / b)\\n\\nprint(get_info2)', '# coding:UTF-8\\ndef get_info2():\\n    a = 10\\n    b = 20\\n    print(a + b)\\n    print(a - b)\\n    print(a * b)\\n    print(a / b)\\n\\nprint(get_info2())', \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info()))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info)    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", \"# coding:UTF-8\\ndef sum_2_num():\\n    result + num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))\\n\\nsum_2_num(30,20)\", '# coding:UTF-8\\ndef test_def(num1, num2, **kwargs):\\n    return (num1 + num2) / kwargs\\n\\nprint(test_def(1, 2, 3, 4, 5))', '# coding:UTF-8\\ndef print_info(name, **urls):\\n    \"\"\"\\n    定义了一个不定长参数的函数值\\n    ：param name: 要输出的姓名信息\\n    : param urls: 一组key=value的信息组合\\n    \"\"\"\\n    print(\"用户姓名：%s\" % name)\\n    print(\"喜欢的技术：\")\\n    for key, value in urls.items():\\n        print(\"\\\\t|- %s: %s\" % (key, value))\\n\\nprint_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clrarng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clrarng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# coding:UTF-8\\ndef print_info(name, **urls):\\n    \"\"\"\\n    定义了一个不定长参数的函数值\\n    ：param name: 要输出的姓名信息\\n    : param urls: 一组key=value的信息组合\\n    \"\"\"\\n    print(\"用户姓名：%s\" % name)\\n    print(\"喜欢的技术：\")\\n    for key, value in urls.items():\\n        print(\"\\\\t|- %s: %s\" % (key, value))\\n\\nprint_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '# 使用globle()函数与locals()函数进行操作\\n# coding:UTF-8\\nnumber = 100\\ndef print_var():\\n    num = 30\\n    info = \"测试的字符串内容\"\\n    print(globals())\\n    print(locals())\\n\\n# 调用函数\\nprint_var()'], 'Out': {1: <function method_val1 at 0x000001DF26E005E0>, 2: <function method_val2 at 0x000001DF26E00D60>, 15: <function sum_2_num at 0x000001DF26E011C0>, 16: 30}, 'get_ipython': <bound method InteractiveShell.get_ipython of <ipykernel.zmqshell.ZMQInteractiveShell object at 0x000001DF2505BF80>>, 'exit': <IPython.core.autocall.ZMQExitAutocall object at 0x000001DF26DB0CE0>, 'quit': <IPython.core.autocall.ZMQExitAutocall object at 0x000001DF26DB0CE0>, 'open': <function open at 0x000001DF24CE7240>, '_': 30, '__': <function sum_2_num at 0x000001DF26E011C0>, '___': <function method_val2 at 0x000001DF26E00D60>, '__session__': 'C:\\\\Users\\\\许家彗\\\\A_Course\\\\def_method.ipynb', '_i': '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '_ii': '# coding:UTF-8\\ndef print_info(name, **urls):\\n    \"\"\"\\n    定义了一个不定长参数的函数值\\n    ：param name: 要输出的姓名信息\\n    : param urls: 一组key=value的信息组合\\n    \"\"\"\\n    print(\"用户姓名：%s\" % name)\\n    print(\"喜欢的技术：\")\\n    for key, value in urls.items():\\n        print(\"\\\\t|- %s: %s\" % (key, value))\\n\\nprint_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '_iii': '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clrarng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '_i1': \"# 无参无返回值函数\\n# coding:UTF-8\\ndef method_val1():\\n    num_a = 10    # 定义一个整数的变量\\n    num_b = 20\\n    print('这是一个无参无返回值函数')    # 输出语句\\n    print(num_a + num_b)    # 输出语句 变量的和\\n\\nmethod_val1    # 函数的调用\", 'method_val1': <function method_val1 at 0x000001DF26E00F40>, '_1': <function method_val1 at 0x000001DF26E005E0>, '_i2': '# 定义无参有返回值函数\\ndef method_val2():\\n    num_a = 10\\n    num_b = 20\\n    return num_a + num_b     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nmethod_val2', 'method_val2': <function method_val2 at 0x000001DF26E00CC0>, '_2': <function method_val2 at 0x000001DF26E00D60>, '_i3': '# 定义无参有返回值函数\\ndef method_val2():\\n    num_a = 10\\n    num_b = 20\\n    return num_a + num_b     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nprint(method_val2)', '_i4': \"# 定义一个无参无返回值函数\\ndef method_val1():\\n    num_a = 10\\n    num_b = 20\\n    print('这是一个无参无返回值函数')     # 说明该函数返回值的内容就是两个整型变量的和\\n\\nprint(method_val1)\", '_i5': '# 定义有参无返回值函数\\ndef method_val3(num_a, num_b):\\n    print(num_a, num_b)    # 此时并没有定义num_a和num_b这两个变量，仅仅只是编写了参数，进行输出\\n\\nmethod_val3(2, 5)    # 在调用有参函数的时候，一定要给该函数传递真实的参数，否则会报错', 'method_val3': <function method_val3 at 0x000001DF26E00A40>, '_i6': '# 定义有参无返回值函数\\ndef method_val3(num_a, num_b):\\n    print(num_a + num_b)    # 此时并没有定义num_a和num_b这两个变量，仅仅只是编写了参数，进行输出\\n\\nmethod_val3(2, 5)    # 在调用有参函数的时候，一定要给该函数传递真实的参数，否则会报错', '_i7': '# 定义有参有返回值函数\\ndef method_val4(num_a, num_b):     # 其中num_a和num_b表示的是形参\\n    return(num_a + num_b) / num_b     # 返回两个参数的和除以其中一个参数\\n\\nprint(method_val4(3, 4))', 'method_val4': <function method_val4 at 0x000001DF26E004A0>, '_i8': \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", 'get_info': <function get_info at 0x000001DF26E01BC0>, '_i9': '# 存在返回值的函数\\ndef get_info3():\\n    pass\\n    return \"HelloWord!\"\\n\\nprint(get_info3())', 'get_info3': <function get_info3 at 0x000001DF26E00900>, '_i10': '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_heool()\\n    return \"AI是新世界世界竞争中的基石\"', 'say_hello': <function say_hello at 0x000001DF26E01260>, 'get_infomsg': <function get_infomsg at 0x000001DF26E014E0>, '_i11': '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递', 'return_data': 'AI是新世界世界竞争中的基石', '_i12': '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递', '_i13': '# 了解了函数的返回值之后，实际上函数还可以相互调用\\n# coding:UTF-8\\ndef say_hello():\\n    \"\"\"\\n    定义一个信息打印函数，该函数不反悔任何数据\\n    \"\"\"\\n    print(\"Hello AI Word!\")\\n\\ndef get_infomsg():\\n    \"\"\"\\n    定义一个获取信息的功能函数\\n    \"\"\"\\n    say_hello()\\n    return \"AI是新世界世界竞争中的基石\"\\n\\n# 将调用的函数赋值给一个容器，该变量（容器、对象）的名称叫做return_data,叫a\\\\b\\\\c\\\\d都可以\\nreturn_data = get_infomsg()    # 引用传递\\nprint(return_data)', '_i14': '# 定义带参数的函数\\n# coding:UTF-8\\ndef echo(title, url):\\n    \"\"\"\\n    实现数据的回显操作，在接受的数据前追加ECHO信息返回\\n    ：param title: 要回显的标题信息\\n    ：param url: 要回显的网页路径信息\\n    : return: 处理后的ECHO信息\\n    \"\"\"\\n    return \"【ECHO】标题路径地址：{}、ip地址：{}\".format(title, url)\\n\\n# 按照函数丁——1参数顺序传入需要的参数\\nprint(echo(\"天气网\",\\'192.168.177.199\\'))    # 调用函数\\n\\nprint(echo(url=\\'192.168.177.199\\', title=\"天气网\"))', 'echo': <function echo at 0x000001DF26E00360>, '_i15': \"# coding:UTF-8\\ndef sum_2_num():\\n    num1 = 10\\n    num2 = 20\\n    return num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))    # 因为该语句处在return语句的后面，所以永远不可能执行\\n\\nsum_2_num\", 'sum_2_num': <function sum_2_num at 0x000001DF26E019E0>, '_15': <function sum_2_num at 0x000001DF26E011C0>, '_i16': \"# coding:UTF-8\\ndef sum_2_num():\\n    num1 = 10\\n    num2 = 20\\n    return num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))    # 因为该语句处在return语句的后面，所以永远不可能执行\\n\\nsum_2_num()\", '_16': 30, '_i17': \"# coding:UTF-8\\ndef function_method():\\n    print('这是一个无参函数')\\n\\ndef test(num1, num2):\\n    if num1 > num2:\\n        print('较大的数是：', num1)\\n    else:\\n        print('较大的数是：', num2)\\n\\ntest(12, 96)\", 'function_method': <function function_method at 0x000001DF26E01620>, 'test': <function test at 0x000001DF26E00E00>, '_i18': \"# coding:UTF-8\\ndef test():\\n    print('hello world')\\n\\ndef test():\\n    print('你好，派森')\\n\\ndemo_project = test()\\nprint(demo_project)    # 因为该函数没有返回值，所以打印的是None\", 'demo_project': None, '_i19': '# coding:UTF-8\\ndef get_info2():\\n    a = 10\\n    b = 20\\n    print(a + b)\\n    print(a - b)\\n    print(a * b)\\n    print(a / b)\\n\\nprint(get_info2)', 'get_info2': <function get_info2 at 0x000001DF26E009A0>, '_i20': '# coding:UTF-8\\ndef get_info2():\\n    a = 10\\n    b = 20\\n    print(a + b)\\n    print(a - b)\\n    print(a * b)\\n    print(a / b)\\n\\nprint(get_info2())', '_i21': \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info()))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", '_i22': \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info)    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", '_i23': \"# coding:UTF-8\\ndef get_info():    # 定义无参无返回值函数\\n    pass    # 此函数没有主体代码，定义时需要写上pass\\nprint(type(get_info))    #<class 'function'>表示当前的get_info是一个函数\\nprint(get_info())    # None表示当前函数没有返回值，所以是None\", '_i24': \"# coding:UTF-8\\ndef sum_2_num():\\n    result + num1 + num2\\n\\n    print('%d + %d = %d' % (num1, num2, result))\\n\\nsum_2_num(30,20)\", '_i25': '# coding:UTF-8\\ndef test_def(num1, num2, **kwargs):\\n    return (num1 + num2) / kwargs\\n\\nprint(test_def(1, 2, 3, 4, 5))', 'test_def': <function test_def at 0x000001DF26E00EA0>, '_i26': '# coding:UTF-8\\ndef print_info(name, **urls):\\n    \"\"\"\\n    定义了一个不定长参数的函数值\\n    ：param name: 要输出的姓名信息\\n    : param urls: 一组key=value的信息组合\\n    \"\"\"\\n    print(\"用户姓名：%s\" % name)\\n    print(\"喜欢的技术：\")\\n    for key, value in urls.items():\\n        print(\"\\\\t|- %s: %s\" % (key, value))\\n\\nprint_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clrarng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', 'print_info': <function print_info at 0x000001DF26FB5260>, '_i27': '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clrarng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '_i28': '# coding:UTF-8\\ndef print_info(name, **urls):\\n    \"\"\"\\n    定义了一个不定长参数的函数值\\n    ：param name: 要输出的姓名信息\\n    : param urls: 一组key=value的信息组合\\n    \"\"\"\\n    print(\"用户姓名：%s\" % name)\\n    print(\"喜欢的技术：\")\\n    for key, value in urls.items():\\n        print(\"\\\\t|- %s: %s\" % (key, value))\\n\\nprint_info(\"AI\",mlearng = \"skylearn, 随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '_i29': '# coding:UTF-8\\ndef print_info(name, age, *inst, **urls):      # *inst就是*args 返回元组， **urls就是**kwargs 返回键值对\\n    print(\"用户姓名：%s，年龄：%d\" % (name, age))    # 输出必选参数\\n    print(\"用户兴趣：\", end=\\'\\')    # 信息输出\\n    for item in inst:   # 遍历可变参数\\n        print(item, end=\\'、\\')    # 打印序列当中的每个元素\\n    print(\"\\\\n 喜欢学习的知识点：\")    # 信息输出\\n    for key, value in urls.items():\\n        print(\"\\\\t | - %s: %s\" % (key, value))    # 输出映射项\\n\\n# 调用函数\\nprint_info(\"张三\", 20, \"卷积神经网络\", \"人工智能对话\", \"大模型\", mlearng = \"skylearn,随机森林,鸢尾花,k-mean,线性回归..\", clearng = \"CNN,pytorch,ResNet,LetNet,Yolo,Opencv..\")', '_i30': '# 使用globle()函数与locals()函数进行操作\\n# coding:UTF-8\\nnumber = 100\\ndef print_var():\\n    num = 30\\n    info = \"测试的字符串内容\"\\n    print(globals())\\n    print(locals())\\n\\n# 调用函数\\nprint_var()', 'number': 100, 'print_var': <function print_var at 0x000001DF26FB67A0>}\n",
      "{'num': 30, 'info': '测试的字符串内容'}\n"
     ]
    }
   ],
   "source": [
    "# 使用globle()函数与locals()函数进行操作\n",
    "# coding:UTF-8\n",
    "number = 100\n",
    "def print_var():\n",
    "    num = 30\n",
    "    info = \"测试的字符串内容\"\n",
    "    print(globals())\n",
    "    print(locals())\n",
    "\n",
    "# 调用函数\n",
    "print_var()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df08455b-7136-4a0c-aa1b-f6cb0f2053cd",
   "metadata": {},
   "source": [
    "获取说明文档信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "760a92a2-8d82-45f7-a117-3188e6c6cbae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "    函数的主要功能是进行信息打印\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "number = 100\n",
    "def print_doc():\n",
    "    \"\"\"\n",
    "    函数的主要功能是进行信息打印\n",
    "    \"\"\"\n",
    "    print(\"Hello Python Hello AI\")\n",
    "\n",
    "print(print_doc.__doc__)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9ca1211-9a66-457a-a928-687febefb8ff",
   "metadata": {},
   "source": [
    "### 闭包\n",
    "Python允许函数进行嵌套定义，即一个函数内部可以继续定义其他函数，将外部函数作为其嵌套内部函数的引用环境，并且在内部函数处理期间，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "a7e8a5ce-792c-4c75-8c65-4a79767d0f01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "加法计算结果：33\n",
      "加法计算结果：66\n"
     ]
    }
   ],
   "source": [
    "# coding:UTF-8\n",
    "def outer_add(n1):    # 定义外部函数\n",
    "    def inner_add(n2):    # 定义内部函数\n",
    "        return n1 + n2    # n1为外部函数的参数，与内部函数的参数n2参数相加\n",
    "    return inner_add    # 返回内部函数引用\n",
    "oa = outer_add(11)    # 接收外部函数引用\n",
    "print(\"加法计算结果：%d\" % oa(22))    # 执行内部函数\n",
    "print(\"加法计算结果：%d\" % oa(55))    # 执行内部函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a379cd14-1ab9-4117-8d76-684c6751cc41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第1次输出数据：cnn.AI.opencv\n",
      "第2次输出数据：AI learning\n",
      "第3次输出数据：AI Nvidia\n"
     ]
    }
   ],
   "source": [
    "# 使用内部函数修改外部函数变量的内容\n",
    "# coding:UTF-8\n",
    "def print_data(count):   #定义一个统计的初始内容\n",
    "    def out(data):    # 内部函数\n",
    "        nonlocal count    #修改外部韩素华变量\n",
    "        count += 1    #修改外部韩素变量\n",
    "        return \"第{}次输出数据：{}\".format(count, data)\n",
    "\n",
    "    return out    # 返回内部函数引用\n",
    "oa = print_data(0)    #接收外部函数引用，从0开始计数\n",
    "print(oa(\"cnn.AI.opencv\"))    #调用内部函数\n",
    "print(oa(\"AI learning\"))      #调用内部函数\n",
    "print(oa(\"AI Nvidia\"))        #调用内部函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c60d8fed-ea2b-42b4-ac70-fd0c4b5af4e7",
   "metadata": {},
   "source": [
    "> 特点：<br/>\n",
    "> 1.集合可以去掉重复的数据\n",
    "> 2.集合数据是无序的，故不支持下标"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf4a8535-33e2-453a-b6bb-461320d0179b",
   "metadata": {},
   "source": [
    "##### 函数返回值的作用\n",
    "- 在程序开发中，有时候，会希望一个函数执行结束后，告诉调用者一个结果，以便使用者针对具体的结果做后续的处理\n",
    "- "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
